#!/usr/bin/python

"""
Catapult controller general interface.
"""

__author__    = 'David Qiu'
__email__     = 'david@davidqiu.com'
__website__   = 'www.davidqiu.com'
__copyright__ = 'Copyright (C) 2017, David Qiu. All rights reserved.'


import math



class TCatapult(object):
  def __init__(self):
    super(TCatapult, self).__init__()

    self.POS_MIN = 0.0 * math.pi
    self.POS_MAX = 1.0 * math.pi

  def _throw_linear(self, pos_init, pos_target, duration):
    raise NotImplementedError('interface not implemented')

  def throw_linear(self, action):
    assert('motion' in action)
    assert(action['motion'] == 'linear')

    assert('pos_init' in action)
    assert(self.POS_MIN <= action['pos_init'] and action['pos_init'] <= self.POS_MAX)

    assert('pos_target' in action)
    assert(self.POS_MIN <= action['pos_target'] and action['pos_target'] <= self.POS_MAX)

    assert(action['pos_init'] < action['pos_target'])

    assert('duration' in action)
    assert(0 < action['duration'])

    return self._throw_linear(action['pos_init'], action['pos_target'], action['duration'])

  def throw(self, action):
    """
    Throw an object by the catapult.

    @param action A dictionary that contains the action parameters.
    @return A dictionary that contains the result parameters.
    """

    assert('motion' in action)

    if action['motion'] == 'linear':
      return self.throw_linear(action)

    else:
      raise ValueError('invalid motion value', action['motion'])

  def _reset(self):
    raise NotImplementedError('interface not implemented')

  def reset(self):
    """
    Reset the catapult.
    """
    return self._reset()


